const Koa = require('koa');
const bodyparser = require('koa-bodyparser');
const Router = require('koa-router');
const dataJson = require('./data.json')

const app = new Koa();
const router = new Router();

app.use(bodyparser());
app.use(router.routes());

router.get('/login', (ctx) => {
    ctx.response.body = '{"name":"ca","age",20}';
});

router.get('/goods', (ctx) => {
    ctx.response.body = dataJson.goods
});

router.post('/userLogin', (ctx, next) => {
    var data = ctx.request.body;
    console.log(data);
    if (data.name == 'ysc' && data.password == '123456') {
        ctx.response.body = '{"error":0,"msg":"登录成功"}';
    } else {
        ctx.response.body = '{"error":1,"msg":"登录失败"}';
    }
});


app.listen(9000, () => {
    console.log('服务器启动成功');
});
